﻿namespace Forest.Lion.Domain.Services {
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using Forest.Lion.Data;
    using Forest.Lion.Model;

    public class DealAppService {
        private readonly IContractRepository _contractRepository;
        private readonly IDealRepository _dealRepository;


        public DealAppService(IContractRepository contractRepository,IDealRepository dealRepository) {
            this._contractRepository = contractRepository;
            this._dealRepository = dealRepository;
        }

        public IEnumerable<Contract> GetContractsForCompany(Guid companyId) {
            var contracts = _contractRepository
                .GetContracts(companyId)
                .Where(c => c.Deleted == false)
                .OrderByDescending(c => c.EndDate)
                .ToList();

            return new ReadOnlyCollection<Contract>(contracts);

        }

        public IEnumerable<Deal> GetDealsForCompany(Guid companyId) {
            var deals = _dealRepository
                .GetDealsForCompany(companyId)
               .Where(d => d.Deleted == false)
               .OrderByDescending(d=>d.DealOn)
               .ToList();

            return new ReadOnlyCollection<Deal>(deals);

        }
    }
}
